<template>
  <div>
    <template>
      <div>
        <el-table
          :data="goodsList"
          style="width: 100%"
          row-key="id"
          border
          lazy
          :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
        >
          <el-table-column prop="id" label="商品编号" width="180">
          </el-table-column>
          <el-table-column prop="goodsname" label="商品名称" width="180">
          </el-table-column>
          <el-table-column prop="price" label="商品价格"> </el-table-column>
          <el-table-column prop="market_price" label="市场价格">
          </el-table-column>
          <el-table-column label="图片">
            <template slot-scope="scope">
              <div>
                <img class="imm" :src="$pre + scope.row.img" alt="" />
              </div>
            </template>
          </el-table-column>
          <el-table-column label="是否新品">
            <template slot-scope="scope">
              <div>
                <el-button type="info" v-if="scope.row.isnew == 1"
                  >是</el-button
                >
                <el-button type="primary" v-else>否</el-button>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="是否热卖">
            <template slot-scope="scope">
              <div>
                <el-button type="info" v-if="scope.row.ishot == 1"
                  >是</el-button
                >
                <el-button type="primary" v-else>否</el-button>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="状态">
            <template slot-scope="scope">
              <div>
                <el-button type="info" v-if="scope.row.status == 1"
                  >启用</el-button
                >
                <el-button type="primary" v-else>禁用</el-button>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="操作">
            <template slot-scope="scope">
              <div>
                <el-button type="info" @click="dit(scope.row.id)"
                  >编辑</el-button
                >
                <v-del @del="del(scope.row.id)"></v-del>
              </div>
            </template>
          </el-table-column>
        </el-table>
        <el-pagination
          background
          layout="prev, pager, next"
          :total="goodstotal"
          :page-size="goodssize"
          @current-change="change"
        >
        </el-pagination>
      </div>
    </template>
  </div>
</template>
<script>
import { mapGetters, mapActions } from "vuex";
import { goodsList, goodsEdit, goodsDel } from "../../../requster/api";
import vDel from "../../../components/del.vue";
export default {
  props: [],
  components: {
    vDel,
  },
  data() {
    return {
      form: [{ msg: "" }],
    };
  },
  computed: {
    ...mapGetters({
      goodsList: "goods/list",
      goodstotal: "goods/total",
      goodssize: "goods/size",
    }),
  },
  methods: {
    //   点击编辑
    dit(id) {
      this.$emit("dit", id);
    },
    change(num) {
      this.reqchangepage(num);
    },
    ...mapActions({
      reqchangelist: "goods/reqchangelist",
      reqchangepage: "goods/reqchangepage",
      reqchangetotal: "goods/reqchangetotal",
    }),
  },
  mounted() {
    this.reqchangepage(1);
    this.reqchangetotal();
  },
};
</script>
<style scoped>
.imm {
  width: 100px;
  height: 100px;
}
</style>